//
//  JSTStarScrollView.m
//  JSTMobClick
//
//  Created by 01 on 16/9/19.
//  Copyright © 2016年 Czj. All rights reserved.
//

#import "JSTStarScrollView.h"
#import "EXTScope.h"

typedef void(^ChangeBlock)();
@interface JSTStarScrollView ()

@property (nonatomic, strong) ChangeBlock changeBlock;

@end

@implementation JSTStarScrollView

-(instancetype)init
{
    if (self = [super init]) {
//        self.frame = CGRectMake(0, 0, kDeviceWidth, kDeviceHeight);
//        self.contentSize = CGSizeMake(kDeviceWidth*5, kDeviceHeight);
    }
    return self;
}

- (void) createContent:(void(^)())end
{
//    @weakify(self);
    self.changeBlock = ^{
//        @strongify(self);
        end();
    };
    
    for (int i = 0; i < 5; i++) {
        UIView *currentView = [[UIView alloc] initWithFrame:CGRectMake(kDeviceWidth*i, 0, kDeviceWidth, kDeviceHeight)];
        currentView.backgroundColor =  RGBCOLOR(arc4random()%256, arc4random()%256, arc4random()%256);
        UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake((kDeviceWidth - kCurrentScreenWidth(120))/2., kDeviceHeight - kCurrentScreenWidth(100), kCurrentScreenWidth(120), kCurrentScreenWidth(40));
        label.backgroundColor = RGBCOLOR(249, 110, 165);
        label.textColor = [UIColor whiteColor];
        label.textAlignment = NSTextAlignmentCenter;
        label.text = [NSString stringWithFormat:@"第%d页", i];
        [currentView addSubview:label];
        if (i == 4) {
            UIButton *changeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            changeBtn.frame = CGRectMake((kDeviceWidth - kCurrentScreenWidth(120))/2., kDeviceHeight - kCurrentScreenWidth(100), kCurrentScreenWidth(120), kCurrentScreenWidth(40));
            [changeBtn setTitle:@"立即体验" forState:UIControlStateNormal];
            changeBtn.titleLabel.textColor = [UIColor whiteColor];
            [changeBtn setBackgroundColor:RGBCOLOR(249, 110, 165)];
            changeBtn.layer.cornerRadius = 5.;
            [changeBtn addTarget:self action:@selector(changeHomePage) forControlEvents:UIControlEventTouchUpInside];
            [currentView addSubview:changeBtn];
        }
        [self addSubview:currentView];
    }
}

- (void) changeHomePage
{
    if (_changeBlock) {
        _changeBlock();
    }
}

@end
